﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OctoOS.UI;
using OctoOS;

public partial class root_admin_confirm : OOSPage
{
    class PathInfo
    {
        [PathInfoMember(0)]
        internal long adID;

        [PathInfoMember(1)]
        internal int days;

        [PathInfoMember(2)]
        internal byte actionType;

        
    }

    PathInfo _pathInfo;

    protected void Page_Init(object sender, EventArgs e)
    {
#warning admin
        //OOSRequest.Current.EnsureModerator();
        _pathInfo = EnablePathInfo<PathInfo>();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (_pathInfo.actionType == (byte)Helper.ActionType.Renew)
        {
            confirmMsgBox.SetContent("Do you really want to renew this ad?");
            Submit yes = confirmMsgBox.AddSubmit("yesbtn", "Yes");
            yes.Click += new EventHandler(OnYesRenewClick);
            Submit no = confirmMsgBox.AddSubmit("nobtn", "No");
            no.Click += new EventHandler(OnNoRenewClick);
        }
        else if (_pathInfo.actionType == (byte)Helper.ActionType.Delete)
        {
            confirmMsgBox.SetContent("Do you really want to delete this ad?");
            Submit yes = confirmMsgBox.AddSubmit("yesbtn", "Yes");
            yes.Click += new EventHandler(OnYesDeleteClick);
            Submit no = confirmMsgBox.AddSubmit("nobtn", "No");
            no.Click += new EventHandler(OnNoDeleteClick);
        }
    }

    private void OnYesRenewClick(object sender, EventArgs e)
    {
        DataSource.ClassifiedAds_Renew(
            OOSRequest.Current.ResourceID,
            _pathInfo.adID,
            _pathInfo.days);
        Response.Redirect(Urls.Classifieds.GetEditAd(_pathInfo.adID));
    }

    private void OnYesDeleteClick(object sender, EventArgs e)
    {
        DataSource.ClassifiedAds_Delete(
            _pathInfo.adID);
        Response.Redirect(Urls.Classifieds.GetMyAds((byte)Helper.AdType.Offer, (byte)Helper.AdStatus.Active));
    }

    private void OnNoRenewClick(object sender, EventArgs e)
    {
        Response.Redirect(Urls.Classifieds.GetEditAd(_pathInfo.adID));
    }

    private void OnNoDeleteClick(object sender, EventArgs e)
    {
        Response.Redirect(Urls.Classifieds.GetInfoAd(_pathInfo.adID));
    }
}